<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>any方法</title>
</head>

<body>
    <!-- 
        Promise下的any方法 只要参数中有一个Promise实例化对象的状态为fulfilled 则整体结果就会为fulfilled
        如果所有的Promise实例都是rejected 那么结果就是rejected
     -->
    <script>
        let p1 = new Promise((resolve, reject) => {
            setTimeout(() => {
                reject('error')
            }, 1000)
        })
        let p2 = new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve('ok,p2')
            }, 3000)
        })
        let p3 = new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve('ok,p3')
            }, 2000)
        })
        // 谁先到且成功以谁为准
        Promise.any([p1, p2, p3]).then(value => {
            console.log(value)
        }, reason => {
            console.log(reason)
        })
        let result = Promise.any([p1, p2, p3])
        console.log(result)
    </script>
</body>

</html>